package com.chinafree.common.utils;

import com.chinafree.business.model.param.ChatParam;
import com.google.gson.GsonBuilder;
import org.springframework.stereotype.Component;

import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;

@Component
public class MessageEntityDecode implements Decoder.Text<ChatParam> {

    @Override
    public ChatParam decode(String s) {
        // 利用 gson 处理消息实体，并格式化日期格式
        return new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss")
                .create()
                .fromJson(s, ChatParam.class);
    }

    @Override
    public boolean willDecode(String s) {
        return true;
    }

    @Override
    public void init(EndpointConfig endpointConfig) {}

    @Override
    public void destroy() {}

}

